Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds validation for the CloudFormation Metadata Context convention (
Metadata.com.aws.cloudformation.Context) at template and resource level. Three Engine-originBestPracticerules run through one shared post-engine pass, so therego,cel, andcompositeselectors produce identical diagnostics.Rules
I4010— missing Context. Reports architecture-relevant resources without a Context block. When two or more resources lack Context, it also reports a template-level architecture summary as missing.W4011— missing rationale. Reports a supplied resource Context block with neither a non-empty literalwhynor a literaltrust.conf: lowdeclaration.W4012— schema violation. Validates every supplied template and resource Context block against the published Metadata Context v1 schema and emits one diagnostic per invalid field.All three rules are registered with
RuleOrigin::Engine. Their IDs are stable engine rule IDs; behavior is derived from the published CloudFormation Context schema and this validator's diagnostics contract.Shared Context validation
validation-engine/src/context_check.rsruns after the selected engine evaluates its rules and before normal diagnostic finalization. The shared pass:I4010aggregation.W4012is active and a Context block is present.Refand canonicalFn::*objects produce explicitW4012diagnostics; transformed-resource fallback markers are canonicalized and never expose internal__intrinsicnames.W4011when the whole Context block or a rationale-bearing value (why,trust, ortrust.conf) is itself an intrinsic;W4012reports the invalid intrinsic directly.mutabilityas the schema requires, including a property namedCondition, while still recognizingRefand canonicalFn::*keys as invalid intrinsic functions.A resource with a usable
Typerequires its own Context block unless it is a subordinate resource type (AWS::IAM::Policy,AWS::Lambda::Permission,AWS::Logs::LogGroup,AWS::Logs::LogStream,AWS::S3::BucketPolicy,AWS::SNS::TopicPolicy, orAWS::SQS::QueuePolicy), a::MODULE, orAWS::CDK::Metadata. Known CDK framework helpers are skipped by logical ID. Context supplied on an exempt resource is still validated byW4011andW4012.Missing resources are aggregated into one
I4010diagnostic anchored at the first resource and list every missingLogicalId (Type); remaining resources are attached throughrelatedResourceswith their source spans. Schema violations are located at the invalid field. The checks intentionally also run on CDK-synthesized templates, whileAWS::CDK::Metadataand known framework helpers remain exempt.Validation behavior
Expected behavior comes from the Metadata Context documentation and schema:
TemplateContextpermitsarch,must,ref, andowner.ResourceContextpermitswhy,must,mutable,mutability,trust, anddeps.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.